home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / Chess++ ƒ / CChessPieces ƒ / CKing.cp < prev    next >
Text File  |  1993-05-26  |  1KB  |  69 lines

  1. ////////////
  2. //
  3. //    CKing.cp
  4. //
  5. //    Chess Piece methods for implementing a King.
  6. //
  7. //    Copyright © 1993 Steven J. Bushell. All rights reserved.
  8. //
  9. ////////////
  10.  
  11. #include <stdlib.h>
  12. #include <string.h>
  13.  
  14. #include "CChessBoard.h"
  15. #include "CChessPiece.h"
  16. #include "CKing.h"
  17.  
  18. extern    CIconHandle    gWhiteKingCicnHandle;
  19. extern    CIconHandle    gBlackKingCicnHandle;
  20.  
  21. void CKing::IKing(Boolean aColor)
  22. {
  23.     inherited::IChessPiece(aColor);
  24.     itsValue = kKingValue;
  25.     canCastle = true;
  26. }
  27.  
  28. void CKing::Draw(short rank, short file)
  29. {
  30.     CIconHandle cicnHandle;
  31.     Rect aRect;
  32.     short rankQD = (rank - 1) << 5, fileQD = (file - 1) << 5;
  33.     
  34.     cicnHandle = (itsColor == White) ? gWhiteKingCicnHandle : gBlackKingCicnHandle;
  35.  
  36.     aRect.left = rankQD;
  37.     aRect.right = rankQD+32;
  38.     aRect.top = fileQD;
  39.     aRect.bottom = fileQD+32;
  40.     PlotCIcon(&aRect,cicnHandle);
  41. }
  42.  
  43. CIconHandle    CKing::GetCicnHandle(void)
  44. {
  45.     return gWhiteKingCicnHandle;
  46. }
  47.  
  48. Boolean    CKing::IsValidMove(CChessBoard *aBoard, short newRank, short newFile)
  49. {
  50.     short    oldRank = aBoard->firstClickRank, oldFile = aBoard->firstClickFile;
  51.  
  52.     if ((abs(oldRank-newRank) <= 1) && (abs(oldFile-newFile) <= 1))
  53.         return true;
  54.  
  55.     if ((abs(oldRank-newRank) == 2) && (canCastle == true))
  56.     {
  57.         if ( 1 )
  58.             ;    //    do castling stuff here
  59.  
  60.     }
  61.  
  62.     return false;
  63. }
  64.  
  65. void CKing::RegisterMove(short rank, short file)
  66. {
  67.     canCastle = false;
  68.     inherited::RegisterMove(rank,file);
  69. }